import pandas as pd

data=\
    {
    "responseCode": 20000,
    "responseDesc": "Success",
    "cityList": [
        {
            "cityId": 21503,
            "name": "神池",
            "enName": "Shenchi",
            "pinYin": "Shenchi",
            "cityTag": [
                "TRAINSTATION",
                "BUSSTATION"
            ],
            "prefectureLevelFlag": 0,
            "provinceId": 11,
            "provinceName": "山西",
            "countryId": 1,
            "countryName": "中国",
            "parentList": [
                {
                    "id": 513,
                    "categoryId": 3,
                    "name": "忻州",
                    "zhName": "忻州",
                    "enName": "Xinzhou"
                },
                {
                    "id": 11,
                    "categoryId": 2,
                    "name": "山西",
                    "zhName": "山西",
                    "enName": "Shanxi"
                },
                {
                    "id": 1,
                    "categoryId": 1,
                    "name": "中国",
                    "zhName": "中国",
                    "enName": "China"
                },
                {
                    "id": 1,
                    "categoryId": 10000,
                    "name": "亚洲",
                    "zhName": "亚洲",
                    "enName": "Asia"
                }
            ],
            "cityTypeTag": []
        },
        {
            "cityId": 21239,
            "name": "武宁",
            "enName": "Wuning",
            "pinYin": "Wuning",
            "cityTag": [
                "BUSSTATION"
            ],
            "prefectureLevelFlag": 0,
            "provinceId": 18,
            "provinceName": "江西",
            "countryId": 1,
            "countryName": "中国",
            "parentList": [
                {
                    "id": 24,
                    "categoryId": 3,
                    "name": "九江",
                    "zhName": "九江",
                    "enName": "Jiujiang"
                },
                {
                    "id": 18,
                    "categoryId": 2,
                    "name": "江西",
                    "zhName": "江西",
                    "enName": "Jiangxi"
                },
                {
                    "id": 1,
                    "categoryId": 1,
                    "name": "中国",
                    "zhName": "中国",
                    "enName": "China"
                },
                {
                    "id": 1,
                    "categoryId": 10000,
                    "name": "亚洲",
                    "zhName": "亚洲",
                    "enName": "Asia"
                }
            ],
            "cityTypeTag": []
        },
        {
            "cityId": 528,
            "name": "依兰",
            "enName": "Yilan",
            "pinYin": "Yilan",
            "cityTag": [
                "TRAINSTATION"
            ],
            "prefectureLevelFlag": 0,
            "provinceId": 5,
            "provinceName": "黑龙江",
            "countryId": 1,
            "countryName": "中国",
            "parentList": [
                {
                    "id": 5,
                    "categoryId": 3,
                    "name": "哈尔滨",
                    "zhName": "哈尔滨",
                    "enName": "Harbin"
                },
                {
                    "id": 5,
                    "categoryId": 2,
                    "name": "黑龙江",
                    "zhName": "黑龙江",
                    "enName": "Heilongjiang"
                },
                {
                    "id": 1,
                    "categoryId": 1,
                    "name": "中国",
                    "zhName": "中国",
                    "enName": "China"
                },
                {
                    "id": 1,
                    "categoryId": 10000,
                    "name": "亚洲",
                    "zhName": "亚洲",
                    "enName": "Asia"
                }
            ],
            "cityTypeTag": []
        }
    ]
}

top_all=[]
for city in data["cityList"]:
    top = {} #top每次都更新，添加下一个字典的前五个键值
    count = 0

    for i, j in city.items():
        if count < 5:
            top[i] = j
            count += 1
        else:
            break
    print(top)
    top_all.append(top)

print("\n--------------")
print(top_all)

df = pd.DataFrame(top_all)

df.to_excel('work_1.xlsx', index=False)